import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';
import '../../provide/shopping_cart.dart';

class CartBottom extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(8),
      color: Colors.white,
      child: Provide<ShoppingCartProvide>(builder: (context,child,scope){
        return Row(
          children: <Widget>[
            _buildSelectAllBtn(context),
            _buildAllPrices(context),
            _buildSettlementBtn(context)
          ],
        );
      }),
    );
  }

  //全选
 Widget _buildSelectAllBtn(context) {
    bool isAllCheck = Provide.value<ShoppingCartProvide>(context).isAllCheck;
    return Container(
      child: Row(
        children: <Widget>[
          Checkbox(value: isAllCheck, onChanged:(value){
            Provide.value<ShoppingCartProvide>(context).changeAllBtnState(value);
          }),
          Text("全选")
        ],
      ),
    );
 }

 //总价
 Widget _buildAllPrices(context) {
   double allPrice = Provide.value<ShoppingCartProvide>(context).allPrice;
    return Expanded(
      flex: 4,
      child: Container(
        padding: EdgeInsets.only(left: 10,right: 10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                Text("合计：",style: TextStyle(fontWeight: FontWeight.bold )),
                Text("￥$allPrice",style: TextStyle(color: Colors.redAccent,fontWeight: FontWeight.bold ),)
              ],
            ),
            SizedBox(height: ScreenUtil().setHeight(8),),
            Text("满十元免配送费,预购免配送费",style: TextStyle(fontSize: ScreenUtil().setSp(20)),),
          ],
        ),
      ),
    );
 }

 //结算
 Widget _buildSettlementBtn(context){
   int allCount = Provide.value<ShoppingCartProvide>(context).allCount;
    return Expanded(
      flex: 2,
      child: Container(
        child: InkWell(
          onTap: (){},
          child: Container(
            padding: EdgeInsets.all(8),
            alignment: Alignment.center,
            decoration: BoxDecoration(
              color: Colors.redAccent,
              borderRadius: BorderRadius.circular(6)
            ),
            child: Text("结算($allCount)",style: TextStyle(color: Colors.white),),
          ),
        )
      ),
    );
 }
}
